package yangsw87.swing;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import java.awt.Font;

import javax.swing.LayoutStyle.ComponentPlacement;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class Group_Layout extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private JTextField uid;
	private JTextField pwd;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			Group_Layout dialog = new Group_Layout();
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 */
	public Group_Layout() {
		setTitle(":: Group Layout ::");
		setBounds(100, 100, 601, 513);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		
		JLabel txtUid = new JLabel("아이디");
		txtUid.setFont(new Font("맑은 고딕", Font.BOLD, 16));
		
		JLabel txtPwd = new JLabel("비밀번호");
		txtPwd.setFont(new Font("맑은 고딕", Font.BOLD, 16));
		
		uid = new JTextField();
		uid.setColumns(10);
		
		pwd = new JTextField();
		pwd.setColumns(10);
		
		JButton loginBtn = new JButton("로그인");
		loginBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String muid = uid.getText();
				String mpwd = pwd.getText();
				
				if (muid.equals("") && !mpwd.equals(""))
					JOptionPane.showMessageDialog(null, "아이디 입력해");
				// muid나 mpwd에 입력된 문자열이
				// 빈값이면 '제대로 입력하라'는 대화상자 표시
				else if (mpwd.equals("") && !muid.equals(""))
					JOptionPane.showMessageDialog(null, "비번 입력해");
				
				else if (muid.equals("") && mpwd.equals(""))
					JOptionPane.showMessageDialog(null, "아이디 비번 입력해");
				
				else if(muid.equals("abc") && mpwd.equals("123"))
					JOptionPane.showMessageDialog(null, "접속완료");
				// muid에 입력된 문자가 abc이고
				// mpwd에 입력된 문자열이 123이면
				// '접속완료'이라는 대화상자 표시
				else
					JOptionPane.showMessageDialog(null, "다시생각해봐");
				// muid에 입력된 문자가 abc가 아니거나
				// mpwd에 입력된 문자열이 123이 아니면
				// '다시생각해봐'라는 대화상자 표시
				
					
			}
		});
		loginBtn.setFont(new Font("돋움체", Font.BOLD, 16));
		
		JLabel lblNewLabel_2 = new JLabel("사용자 등록");
		
		JLabel lblNewLabel_3 = new JLabel("ID/PW 찾기");
		
		JLabel lblNewLabel = new JLabel("|");
		GroupLayout gl_contentPanel = new GroupLayout(contentPanel);
		gl_contentPanel.setHorizontalGroup(
			gl_contentPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPanel.createSequentialGroup()
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPanel.createSequentialGroup()
							.addGap(138)
							.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING, false)
								.addGroup(gl_contentPanel.createSequentialGroup()
									.addComponent(txtPwd)
									.addGap(18)
									.addComponent(pwd, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
								.addGroup(gl_contentPanel.createSequentialGroup()
									.addComponent(txtUid)
									.addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
									.addComponent(uid, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
							.addGap(18)
							.addComponent(loginBtn))
						.addGroup(gl_contentPanel.createSequentialGroup()
							.addGap(201)
							.addComponent(lblNewLabel_2)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(lblNewLabel)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(lblNewLabel_3)))
					.addContainerGap(138, Short.MAX_VALUE))
		);
		gl_contentPanel.setVerticalGroup(
			gl_contentPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPanel.createSequentialGroup()
					.addContainerGap(175, Short.MAX_VALUE)
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(txtUid)
						.addComponent(uid, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(18)
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(txtPwd)
						.addComponent(pwd, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(34)
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel_2)
						.addComponent(lblNewLabel_3)
						.addComponent(lblNewLabel))
					.addGap(141))
				.addGroup(gl_contentPanel.createSequentialGroup()
					.addGap(178)
					.addComponent(loginBtn, GroupLayout.DEFAULT_SIZE, 66, Short.MAX_VALUE)
					.addGap(187))
		);
		contentPanel.setLayout(gl_contentPanel);
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("확인");
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
		}
	}
}
